package com.example.snow.service.impl;

import com.example.snow.service.OrderService;
import com.example.snow.util.IdGeneratorSnowFlake;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

@Service
public class OrderServiceImpl implements OrderService {

    @Resource
    private IdGeneratorSnowFlake idGeneratorSnowFlake;

    @Override
    public String getIdBySnowFlake()
    {
        ExecutorService threadPool = Executors.newFixedThreadPool(5);

        for (int i = 0; i < 20; i++) {
            threadPool.submit(()->{
                System.out.println(idGeneratorSnowFlake.snowFlakeId());
            });
        }
        threadPool.shutdown();
        return "hello snowflake";
    }
}
